<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/11
 * Time: 9:57
 */

namespace Admin\Model;
use Think\Model;


class ConsultingModel extends Model
{
    protected  $tableName = 'consulting';

    protected $_auto = array (
//        array('reply_time','time',3,'function'),
//        array('reply_id','getUserId',3,'callback')
    );

    public function getUserId(){
        return session('userId');
    }

    public function getConsultingList($where,$size){
        $data['count'] = $this->where($where)->count();
        if ($size) {
            $pageInfo = getPage($data['count'],$size);
            $data['list'] = $this->where($where)->limit($pageInfo->firstRow,$pageInfo->listRows)->order('id desc')->select();
            $data['pageInfo'] = $pageInfo;
            $data['page'] = $pageInfo->show();
            $data['nowPage'] = $pageInfo->nowPage ? $pageInfo->nowPage : 0;
        }else{
            $data['list'] = $this->where($where)->order('id desc')->select();
        }
        return $data;
    }
//api获取咨询列表
    public function getApiConsulList($where=array(),$curPage=1,$pageSize=15,$order='id desc') {
        $data = array();
        $count = $this->where($where)->count();
        $totalPage = ceil($count/$pageSize);
        $curPage = ($curPage > 0) ? $curPage : 1;
        $firstRow = ($curPage-1)*$pageSize;
        $dataList = $this->where($where)->order($order)->limit($firstRow,$pageSize)->select();
        $data['list'] = $dataList;
        $data['count'] = $count;
        $data['curPage'] = $curPage;
        $data['totalPage'] = $totalPage;
        return $data;
    }

    //删除咨询
    public function delConsultById($id,$data){
        $where = array(
            'id' => array('eq',$id)
        );
        return $this->where($where)->save($data);
    }
}